from django.contrib.auth import get_user_model
from rest_framework import viewsets,permissions
from  .serializers import UserSerializer
from .filters import UserFilter
from django_filters.rest_framework import DjangoFilterBackend

User = get_user_model()
class UserViewSet(viewsets.ModelViewSet):
    '''
    retireve:
        获取指定user记录
    list:
        获取user列表
    update:
        更新IDC记录
    particial_update:
        更新user部分字段
    destroy:
        删除user记录
    create:
        新增user记录
    '''
    queryset = User.objects.all()
    serializer_class = UserSerializer
    # def get_queryset(self):
    #     queryset = super(UserViewSet, self).get_queryset()
    #     queryset = queryset.filter(username__icontains=self.request.query_params.get("username"))
    #     return queryset
    #filter_backends = (DjangoFilterBackend,)   在settings设置全局
    filter_class = UserFilter
    permission_classes = (permissions.IsAuthenticated,
                          permissions.DjangoModelPermissions,)

    filter_fields = ("username",)
